<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

/**
 * 排班数据表
 *
 * Date: 05/05/2018
 * @author George
 */
class CreateSchedulesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('schedules', function (Blueprint $table) {
            $table->increments('id');
			$table->unsignedInteger('company_id')->index()->comment('公司ID');
			$table->unsignedInteger('project_id')->index()->comment('项目ID');
			$table->unsignedInteger('genre_id')->index()->comment('班次ID');
			$table->unsignedInteger('demand_id')->index()->comment('需求ID');
			$table->unsignedInteger('user_id')->index()->comment('人员ID');
			$table->string('genre_name')->index()->comment('班次名称');
			$table->date('date')->index()->comment('日期');
			$table->time('start')->comment('开始时间');
			$table->time('end')->comment('结束时间');
			$table->timestamp('start_timestamp')->nullable()->comment('具体开始时间');
			$table->timestamp('end_timestamp')->nullable()->comment('具体结束时间');
			$table->unsignedInteger('worktime')->comment('工作时长');
			$table->unsignedInteger('line_id')->default(0)->index()->comment('巡检线路ID');
			$table->boolean('span')->default(false)->comment('是否跨天');
            $table->timestamps();
            $table->unique(['project_id', 'demand_id', 'user_id']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('schedules');
    }
}
